Class sjl.InputStreamIterator
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sjl.InputStreamIterator

java.lang.Object
   |
   +----sjl.Iter
           |
           +----sjl.InputStreamIterator

public class InputStreamIterator
extends Iter
implements InputIterator
To make it possible for the generic algorihms to work directly with input streams, the InputStreamIterator have been created.
Ex:
    fin = new FileInputStream("inputfile");
    InputStreamIterator is = new InputStreamIterator(fin, new ReadIntegerText());
    InputStreamIterator ie = new InputStreamIterator();
    Algo.copy(is, ie, new BackInsertIterator(vector));
The InputStreamIterator reads (using the ReadIntegerText function object) successive elements from the input stream (fin) for which it was contructed. When the InputStreamIterator is contructed, and every time next() is used, the iterator reads and stores a value. If the end of the stream is reached (the stream throws a EOFException), the iterator becomes equal to the iterator end-of-stream iterator value. The constructor with no arguments always contructs an end of stream iterator object which is the only legitimate iterator to be used for the end condition.

It is impossible to store things into a InputStreamIterator.

The main peculiarity of the InputStreamIterator is the fact that the next() method is not equality preservings, that is i.cmp(j) does not guarantee at all that i.next(); j.next(); i.cmp(j). Every time next() is used a new value is returned.

The practical consequence of this fact is that InputStreamIterators can be used only for one-pass algorithms, which actually makes perfect sense, since for multi-pass algorithms it is always more appropriate to use inmemory data structures.

Two end-of-stream iterators are always equal. An end-of-stream iterator is not equal to a non-end-of-stream iterator.

Copyright © 1996 Finn Bock


Constructor Index

 o InputStreamIterator()
Construct a end-of-stream InputStreamIterator.
 o InputStreamIterator(DataInputStream, Function1)
Construct a InputStreamIterator for the stream using the function object as a reader.
 o InputStreamIterator(InputStream, Function1)
Construct a InputStreamIterator for the stream using the function object as a reader.

Method Index

 o cmp(Iterator)
Compare two iterators.
 o genericCopy()
XXX: Is this possible???
 o get()
Return the current value.
 o next()
Advance the iterator to the next element.

Constructors

 o InputStreamIterator
  public InputStreamIterator(InputStream istream,
                             Function1 func)
Construct a InputStreamIterator for the stream using the function object as a reader.
Parameters:
istream - The iterator is constructed for this stream. A DataInputStream is constructed for istream.
func - The function object used as a reader.
See Also:
DataInputStream
 o InputStreamIterator
  public InputStreamIterator(DataInputStream istream,
                             Function1 func)
Construct a InputStreamIterator for the stream using the function object as a reader.
Parameters:
istream - The iterator is constructed for this stream.
 o InputStreamIterator
  public InputStreamIterator()
Construct a end-of-stream InputStreamIterator.
XXX: perhaps a static variable is better.

Methods

 o get
  public Object get()
Return the current value. If called multiple times, the same value is returned.
 o next
  public Iterator next()
Advance the iterator to the next element. A new value is read.
 o cmp
  public boolean cmp(Iterator iterator)
Compare two iterators.
Returns:
true if both iterators are non-end-of-stream or end-of-stream.
 o genericCopy
  public Iterator genericCopy()
XXX: Is this possible???
Returns:
this

All Packages  Class Hierarchy  This Package  Previous  Next  Index